package cn.edu.hunau.java.week02.day04.com;

import org.junit.Test;

import java.util.Arrays;
import java.util.Comparator;

public class UserSortTest {
    @Test
    public void defaultSortTest(){
        User[] users=initData();
        Arrays.sort(users);
        System.out.println(Arrays.toString(users));
    }

    public User[] initData(){
        User[] users=new User[5];
        users[0]=new User(1001,"Lucy");
        users[1]=new User(22,"zhangmazi");
        users[2]=new User(312,"huangsilang");
        users[3]=new User(4123,"xianzhang");
        users[4]=new User(523,"shiye");

        return users;
    }

    @Test
    public void customSortTest(){
        User[] users=initData();
        Arrays.sort(users,new User.SortByStringLength());
        System.out.println(Arrays.toString(users));
    }

    @Test
    public void customSortTest01(){
        User[] users=initData();
        Arrays.sort(users,new Comparator<User>(){
            @Override
            public int compare(User o1, User o2) {
                return o1.getName().length()-o2.getName().length();
            }
        });
        System.out.println(Arrays.toString(users));
    }

    @Test
    public void customSortTest02(){
        User[] users=initData();
        Arrays.sort(users,(o1,o2)->o1.getName().length()-o2.getName().length());
        System.out.println(Arrays.toString(users));
    }

    @Test
    public void customSortTest03(){
        String[] arr={"C++","Java","Web","Spring Boot","Python"};
        Arrays.sort(arr,(s1,s2)->s1.length()-s2.length());
        System.out.println(Arrays.toString(arr));
    }

    @Test
    public void test(){
        int maxValue=Integer.MIN_VALUE;
        System.out.println(maxValue);
        String binaryString=Integer.toBinaryString(maxValue);
        System.out.println(binaryString);
        String hexString=Integer.toHexString(maxValue);
        System.out.println(hexString);
        String str="123";
        int i=Integer.parseInt(str);
        System.out.println(i);
    }

    @Test
    public void test01(){
        Integer[] arr={5,3,45,6,67,35,674,356,75,754};
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));
        Arrays.sort(arr,(a,b)->b-a);
        System.out.println(Arrays.toString(arr));
    }
}